import Toast from './Toast.vue'

function createToast({Vue,message,propsData}: any){
    const Constructor = Vue.extend(Toast)
    const toast = new Constructor({
        propsData
    })
    toast.$slots.default = [message]
    toast.$mount()
    document.body.appendChild(toast.$el)
    return toast
}

let currentToast: any
export default {
    install(Vue: any, options: any) {
        Vue.prototype.$toast = function (message: string,toastOptions: any) {
            if(currentToast){currentToast.close()}
            currentToast = createToast({Vue,message,propsData:toastOptions})

        }
    }
}